clear


set more off

use "data/dataCOLOGNE.dta", replace


// Data management 
if 1 {

	rename switchBack multipleSwitchingRisk
	

	gen winKnown = win * known
	replace priorNum = priorNum / 100

	gen highInc = win > 3
	replace highInc = . if win == 0
	gen highInc_known = highInc * known
	
	gen win_known = win*known

	cap drop lose
	gen lose = abs(win - 6)
	replace lose = 6 if catastropheTreatment == 1
	
	gen betCE = bet * minCE
	replace betCE = . if win == 0
	
	// gen betCEpred = bet * predCE
	// replace betCEpred = . if win == 0
	
	gen firstHalf = order <= 16
	
	gen condition = .
	replace condition = 1  if known == 1 & catastropheTr == 1 & prior == "low"  & delayTr == 1
	replace condition = 2  if known == 1 & catastropheTr == 1 & prior == "mid"  & delayTr == 1
	replace condition = 3  if known == 1 & catastropheTr == 1 & prior == "high" & delayTr == 1
	replace condition = 4  if known == 1 & catastropheTr == 0 & prior == "low"  & delayTr == 1
	replace condition = 5  if known == 1 & catastropheTr == 0 & prior == "mid"  & delayTr == 1
	replace condition = 6  if known == 1 & catastropheTr == 0 & prior == "high" & delayTr == 1
	replace condition = 7  if known == 0 & catastropheTr == 1 & prior == "low"  & delayTr == 1
	replace condition = 8  if known == 0 & catastropheTr == 1 & prior == "mid"  & delayTr == 1
	replace condition = 9  if known == 0 & catastropheTr == 1 & prior == "high" & delayTr == 1
	replace condition = 10 if known == 0 & catastropheTr == 0 & prior == "low"  & delayTr == 1
	replace condition = 11 if known == 0 & catastropheTr == 0 & prior == "mid"  & delayTr == 1
	replace condition = 12 if known == 0 & catastropheTr == 0 & prior == "high" & delayTr == 1
	
	replace condition = 13   if known == 1 & catastropheTr == 1 & prior == "low"  & delayTr == 0
	replace condition = 14   if known == 1 & catastropheTr == 1 & prior == "mid"  & delayTr == 0
	replace condition = 15   if known == 1 & catastropheTr == 1 & prior == "high" & delayTr == 0
	replace condition = 16   if known == 1 & catastropheTr == 0 & prior == "low"  & delayTr == 0
	replace condition = 17   if known == 1 & catastropheTr == 0 & prior == "mid"  & delayTr == 0
	replace condition = 18   if known == 1 & catastropheTr == 0 & prior == "high" & delayTr == 0
	replace condition = 19   if known == 0 & catastropheTr == 1 & prior == "low"  & delayTr == 0
	replace condition = 20   if known == 0 & catastropheTr == 1 & prior == "mid"  & delayTr == 0
	replace condition = 21   if known == 0 & catastropheTr == 1 & prior == "high" & delayTr == 0
	replace condition = 22   if known == 0 & catastropheTr == 0 & prior == "low"  & delayTr == 0
	replace condition = 23   if known == 0 & catastropheTr == 0 & prior == "mid"  & delayTr == 0
	replace condition = 24   if known == 0 & catastropheTr == 0 & prior == "high" & delayTr == 0

	
	la de cond 	 1 "known, cat, delay, low " ///
				 2 "known, cat, delay, mid " ///
				 3 "known, cat, delay, high" ///
				 4 "known, noCat, delay, low " ///
				 5 "known, noCat, delay, mid " ///
				 6 "known, noCat, delay, high" ///
				 7 "unknown, cat, delay, low " ///
				 8 "unknown, cat, delay, mid " ///
				 9 "unknown, cat, delay, high" ///
				10 "unknown, noCat, delay, low " ///
				11 "unknown, noCat, delay, mid " ///
				12 "unknown, noCat, delay, high" ///
				13 "known, cat, noDelay, low " ///
				14 "known, cat, noDelay, mid " ///
				15 "known, cat, noDelay, high" ///
				16 "known, noCat, noDelay, low " ///
				17 "known, noCat, noDelay, mid " ///
				18 "known, noCat, noDelay, high" ///
				19 "unknown, cat, noDelay, low " ///
				20 "unknown, cat, noDelay, mid " ///
				21 "unknown, cat, noDelay, high" ///
				22 "unknown, noCat, noDelay, low " ///
				23 "unknown, noCat, noDelay, mid " ///
				24 "unknown, noCat, noDelay, high" 
	
	la val cond cond
	
	
	gen cond2 = condition
	replace cond2 = condition - 6 if condition >= 7 & condition <= 12
	replace cond2 = condition - 6 if condition >= 19 & condition <= 24
	
	
	gen minCElower = .
	replace minCElower = -6 	if round(10*minCEhigh) ==  -60
	replace minCElower = -6 	if round(10*minCEhigh) ==  -45
	replace minCElower = -4.5  	if round(10*minCEhigh) ==  -30
	replace minCElower = -3  	if round(10*minCEhigh) ==  -15
	replace minCElower = -1.5  	if round(10*minCEhigh) ==  -05
	replace minCElower = -0.5 	if round(10*minCEhigh) ==  0 
	replace minCElower = 0 		if round(10*minCEhigh) ==  05 
	replace minCElower = 0.5 	if round(10*minCEhigh) ==  15 
	replace minCElower = 1.5 	if round(10*minCEhigh) ==  30 
	replace minCElower = 3 		if round(10*minCEhigh) ==  45 
	replace minCElower = 4.5 	if round(10*minCEhigh) ==  60
	

	gen adviceFollowed = bet == signal
	gen advicePositiveFollowed = (bet == 1) if (signal == 1)
	gen adviceNegativeFollowed = (bet == 0) if (signal == 0)
	
	// Define weights to account for stochastic signal realizations
	if 1 {
		
		// In each condition, should see 75% positive signals for those who select 
		// positively skewed information structure and 25% negative signals for 
		// those who select negatively skewed information structure. 
		
		cap gen weight = . 
		forvalues condition = 1 / 24 {
			foreach winAmt in 0 1 2 4 5  {
				local conditionInner = "condition == `condition' & win == `winAmt'"
				
				su priorNum if `conditionInner'
				local prior = r(mean)
				
				//(`prior'*1 + (1 - `prior')*0.5)
			
				su signal 							if `conditionInner' & infoStr == 1
				replace weight = (`prior'*1 + (1 - `prior')*0.5) 		/ r(mean)			if signal == 1 & `conditionInner' & infoStr == 1
				replace weight = (1- (`prior'*1 + (1 - `prior')*0.5)) 	/ (1 - r(mean)) 	if signal == 0 & `conditionInner' & infoStr == 1

				su signal 							if `conditionInner' & infoStr == 0
				replace weight = (`prior'*0.5 + (1 - `prior')*0) 		 / r(mean)			if signal == 1 & `conditionInner' & infoStr == 0
				replace weight = (1- (`prior'*0.5 + (1 - `prior')*0)) 	 / (1 - r(mean)) 	if signal == 0 & `conditionInner' & infoStr == 0
			}
		}
				
		reg signal [pw=weight] if infoStr == 1 & prior == "low"
		reg signal [pw=weight] if infoStr == 1 & prior == "mid"
		reg signal [pw=weight] if infoStr == 1 & prior == "high"
		reg signal [pw=weight] if infoStr == 0 & prior == "low"
		reg signal [pw=weight] if infoStr == 0 & prior == "mid"
		reg signal [pw=weight] if infoStr == 0 & prior == "high"
		reg signal if infoStr == 1
		
		reg winProb [pw = weight] if prior == "low"
		reg winProb [pw = weight] if prior == "mid"
		reg winProb [pw = weight] if prior == "high"
		
		reg winProb  if prior == "low"
		reg winProb  if prior == "mid"
		reg winProb  if prior == "high"
		
		
		
	
		cap gen winAmt = win
		cap gen weightState = . 
		forvalues condition = 1 / 24 {
			foreach winAmt in 0 1 2 4 5 {
				local conditionInner = "condition == `condition' & winAmt == `winAmt'"
				
				su priorNum if `conditionInner'
				local prior = r(mean) / 100
				
			
				su state 							if `conditionInner'
				di `prior'
				di r(mean)
				di `winAmt'
				replace weightState = `prior' / r(mean)				if state == 1 & `conditionInner' 
				replace weightState = (1- `prior') 	/ (1 - r(mean)) if state == 0 & `conditionInner' 
			}
		}
		
		// drop data about that's about risk without corresponding info decision

		drop if bet == .

	
		// Define variables
		
		cap drop loss
		
		cap gen beliefDiff = belief - winProb
		cap gen loser = betCE < 0
		cap gen loss = min(betCE, 0)
		cap gen gain = max(betCE, 0)
		replace loss = . if betCE == .
		replace gain = . if betCE == .


		// cap gen lossPred = min(betCEpred, 0)
		// cap gen gainPred = max(betCEpred, 0)
		// replace lossPred = . if betCEpred == .
		// replace gainPred = . if betCEpred == .		
			
	}
	


}


// Tables 
if 1 {
	// Supplementary Table: Information choice
	if 1 {
		
		local prior = "low"
		reg infoStr win known win_known if prior == "`prior'" ///
			, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableInfoChoiceLong1.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) replace

		reg infoStr win known win_known if prior == "`prior'" ///
			& catastropheTr == 0 & delayTr == 0, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableInfoChoiceLong1.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg infoStr win known win_known if prior == "`prior'" ///
			& catastropheTr == 1 & delayTr == 0, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableInfoChoiceLong1.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg infoStr win known win_known if prior == "`prior'" ///
			& catastropheTr == 0 & delayTr == 1, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableInfoChoiceLong1.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg infoStr win known win_known if prior == "`prior'" ///
			& catastropheTr == 1 & delayTr == 1, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableInfoChoiceLong1.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		

		
		local prior = "mid"
		reg infoStr win known win_known if prior == "`prior'" ///
			, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableInfoChoiceLong2.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) replace

		reg infoStr win known win_known if prior == "`prior'" ///
			& catastropheTr == 0 & delayTr == 0, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableInfoChoiceLong2.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg infoStr win known win_known if prior == "`prior'" ///
			& catastropheTr == 1 & delayTr == 0, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableInfoChoiceLong2.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg infoStr win known win_known if prior == "`prior'" ///
			& catastropheTr == 0 & delayTr == 1, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableInfoChoiceLong2.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg infoStr win known win_known if prior == "`prior'" ///
			& catastropheTr == 1 & delayTr == 1, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableInfoChoiceLong2.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		

		
		local prior = "high"
		reg infoStr win known win_known if prior == "`prior'" ///
			, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableInfoChoiceLong3.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) replace

		local prior = "high"
		reg infoStr win known win_known if prior == "`prior'" ///
			& catastropheTr == 0 & delayTr == 0, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableInfoChoiceLong3.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg infoStr win known win_known if prior == "`prior'" ///
			& catastropheTr == 1 & delayTr == 0, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableInfoChoiceLong3.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg infoStr win known win_known if prior == "`prior'" ///
			& catastropheTr == 0 & delayTr == 1, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableInfoChoiceLong3.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg infoStr win known win_known if prior == "`prior'" ///
			& catastropheTr == 1 & delayTr == 1, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableInfoChoiceLong3.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		
	}
		
	// Supplementary Table: Participation
	if 1 {
		
		local prior = "low"
		reg bet win known win_known if prior == "`prior'" ///
			, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableBetLong1.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) replace

		reg bet win known win_known if prior == "`prior'" ///
			& catastropheTr == 0 & delayTr == 0, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableBetLong1.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg bet win known win_known if prior == "`prior'" ///
			& catastropheTr == 1 & delayTr == 0, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableBetLong1.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg bet win known win_known if prior == "`prior'" ///
			& catastropheTr == 0 & delayTr == 1, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableBetLong1.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg bet win known win_known if prior == "`prior'" ///
			& catastropheTr == 1 & delayTr == 1, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableBetLong1.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		

		
		local prior = "mid"
		reg bet win known win_known if prior == "`prior'" ///
			, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableBetLong2.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) replace

		reg bet win known win_known if prior == "`prior'" ///
			& catastropheTr == 0 & delayTr == 0, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableBetLong2.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg bet win known win_known if prior == "`prior'" ///
			& catastropheTr == 1 & delayTr == 0, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableBetLong2.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg bet win known win_known if prior == "`prior'" ///
			& catastropheTr == 0 & delayTr == 1, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableBetLong2.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg bet win known win_known if prior == "`prior'" ///
			& catastropheTr == 1 & delayTr == 1, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableBetLong2.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		

		
		local prior = "high"
		reg bet win known win_known if prior == "`prior'" ///
			, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableBetLong3.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) replace

		local prior = "high"
		reg bet win known win_known if prior == "`prior'" ///
			& catastropheTr == 0 & delayTr == 0, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableBetLong3.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg bet win known win_known if prior == "`prior'" ///
			& catastropheTr == 1 & delayTr == 0, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableBetLong3.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg bet win known win_known if prior == "`prior'" ///
			& catastropheTr == 0 & delayTr == 1, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableBetLong3.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		reg bet win known win_known if prior == "`prior'" ///
			& catastropheTr == 1 & delayTr == 1, cl(id)
		local subj =  e(N_clust)
		outreg2 using "../writeup/tables/tableBetLong3.tex", addstat("Subj", `subj') adec(0) tex(frag) dec(3) 
		
		
	}

	// Supplementary Table B.2.B
	// and 
	// Supplementary Table B.3.B
	// and
	// Supplementary Table B.4.B
	if 1 {
		
		// Welfare table main (Supplementary Table B.2.B)
		if 1 {
			
			cap drop winMin
			gen winMin = win - 1
			replace winMin = . if win == 0
			
			set seed 1
			
			mysureg (gain winMin) /// 
					(loss winMin) ///
					if known == 1 & catastrophe == 0 ///
					, vce(cluster id)

			local mMin = 0
			noisily: nlcom   (eq1:(([gain]_cons + `mMin'*[gain]win) / (([gain]_cons + `mMin'*[gain]win) - ([loss]_cons +  `mMin'*[loss]win))) ///
					- ([gain]win / ([gain]win - [loss]win))) ///
					(eq2:([gain]win / ([gain]win - [loss]win))) ///						
					, post
			

			mysureg (gain winMin) /// 
					(loss winMin) ///
					if known == 1 & catastrophe == 1 ///
					, vce(cluster id)			
			
			set seed 1
			
			
					
			mysureg (gain winMin) /// 
					(loss winMin) ///
					if known == 1 ///
					, vce(cluster id)

			local mMin = 0
			noisily: nlcom   (eq1:(([gain]_cons + `mMin'*[gain]win) / (([gain]_cons + `mMin'*[gain]win) - ([loss]_cons +  `mMin'*[loss]win))) ///
					- ([gain]win / ([gain]win - [loss]win))) ///
					(eq2:([gain]win / ([gain]win - [loss]win))) ///						
					, post
					

					
					
			mysureg (gain winMin) /// 
					(loss winMin) ///
					if known == 0 ///
					, vce(cluster id)

			
			local mMin = 0
			nlcom   (eq1:(([gain]_cons + `mMin'*[gain]win) / (([gain]_cons + `mMin'*[gain]win) - ([loss]_cons +  `mMin'*[loss]win))) ///
					- ([gain]win / ([gain]win - [loss]win))) ///
					(eq2:([gain]win / ([gain]win - [loss]win))) ///						
					, post		

		
			cap postclose welfareTable
			postfile welfareTable ///
					 aG str3 starsGainA double aL str3 starsLossA ///
					 bG str3 starsGain double bL str3 starsLoss ///
					 double alphaMin str4 starsAlpha ///
					 double alphaMax str4 starsAlphaMax ///
					 str4 cond double p ///
					 using "data/welfareTable.dta", replace
			
			foreach cond2 of numlist 1/6 13/18 {
				preserve 
					
					keep if known == 1
					keep if cond2 == `cond2'
					set seed 1
					
					mysureg (gain win) /// 
							(loss win) ///
						, vce(cluster id)
				
				
				
				
				
					
					local mMin = 1
					local mMax = 5
					
					// Condition
					nlcom   (eq1:(([gain]_cons + `mMin'*[gain]win) / (([gain]_cons + `mMin'*[gain]win) - ([loss]_cons +  `mMin'*[loss]win))) ///
							- ([gain]_cons + `mMax'*[gain]win) / (([gain]_cons + `mMax'*[gain]win) - ([loss]_cons +  `mMax'*[loss]win))) ///
							(eq2: (([gain]_cons + `mMax'*[gain]win) / (([gain]_cons + `mMax'*[gain]win) - ([loss]_cons +  `mMax'*[loss]win)))) ///	
							(eq3: ([gain]_cons + `mMin'*[gain]win)) ///
							(eq4: ([loss]_cons + `mMin'*[loss]win)) ///
							(eq5: (([gain]_cons + `mMin'*[gain]win) / (([gain]_cons + `mMin'*[gain]win) - ([loss]_cons +  `mMin'*[loss]win)))) ///
							(eq6: ([gain]_cons + `mMax'*[gain]win)) ///
							(eq7: ([loss]_cons + `mMax'*[loss]win)) ///
						, post
					
					// New
					
					
					local bG = _b[eq6]
					local bL = _b[eq7]
					local seBg = _se[eq6] 
					local seBl = _se[eq7]
					
					test eq6 == 0
					local pGain = r(p)
					test eq7 == 0
					local pLoss = r(p)
					
					
					local starsGain = ""
					if (`pGain' <= 0.01) {
						local starsGain = "***"
					}
					if (`pGain' <= 0.05 & `pGain'>0.01) {
						local starsGain = "**"
					}
					if (`pGain' < 0.1 & `pGain'>0.05) {
						local starsGain = "*"
					}
					
					
					local starsLoss = ""
					if (`pLoss' <= 0.01) {
						local starsLoss = "***"
					}
					if (`pLoss' <= 0.05 & `pLoss'>0.01) {
						local starsLoss = "**"
					}
					if (`pLoss' < 0.1 & `pLoss'>0.05) {
						local starsLoss = "*"
					}
					
					
					
					
					// Previous
					
					local alphaMin = _b[eq2]
					local alphaSE = _se[eq2]
					local alphaMax = _b[eq5]
					local alphaMaxSE = _se[eq5]
					
					test eq2 == 0
					local pAlpha = r(p)
					
					local starsAlpha = ""
					if (`pAlpha' <= 0.01) {
						local starsAlpha = "***"
					}
					if (`pAlpha' <= 0.05 & `pAlpha'>0.01) {
						local starsAlpha = "**"
					}
					if (`pAlpha' < 0.1 & `pAlpha'>0.05) {
						local starsAlpha = "*"
					}

					local possibilityCond = "No"
					if (_b[eq1] >= 0) {
						local possibilityCond = "Yes"
					}
					
					
					test eq5 == 1
					local pAlphaMax = r(p)
					
					local starsAlphaMax = ""
					if (`pAlphaMax' <= 0.01) {
						local starsAlphaMax = "***"
					}
					if (`pAlphaMax' <= 0.05 & `pAlpha'>0.01) {
						local starsAlphaMax = "**"
					}
					if (`pAlphaMax' < 0.1 & `pAlpha'>0.05) {
						local starsAlphaMax = "*"
					}

					local possibilityCond = "No"
					if (_b[eq1] >= 0) {
						local possibilityCond = "Yes"
					}
					
					
					local aG = _b[eq3]
					local aGse = _se[eq3]
					local aL = _b[eq4]
					local aLse = _se[eq4]
					
					
					
					test _b[eq3] == 0
					local pGainA = r(p)
					test _b[eq4] == 0
					local pLossA = r(p)
					
					
					local starsGainA = ""
					if (`pGainA' <= 0.01) {
						local starsGainA = "***"
					}
					if (`pGainA' <= 0.05 & `pGainA'>0.01) {
						local starsGainA = "**"
					}
					if (`pGainA' < 0.1 & `pGainA'>0.05) {
						local starsGainA = "*"
					}
					
					
					local starsLossA = ""
					if (`pLossA' <= 0.01) {
						local starsLossA = "***"
					}
					if (`pLossA' <= 0.05 & `pLossA'>0.01) {
						local starsLossA = "**"
					}
					if (`pLossA' < 0.1 & `pLossA'>0.05) {
						local starsLossA = "*"
					}
					
					
					noisily: di "`possibilityCond'"
							
					test eq1
					local pTest = r(p)

					
				restore
				post welfareTable ///
					(`aG') ("`starsGainA'") (`aL') ("`starsLossA'")  ///
					(`bG') ("`starsGain'") (`bL') ("`starsLoss'") ///
					(`alphaMin') ("`starsAlpha'") (`alphaMax') ("`starsAlphaMax'") ///
					("`possibilityCond'") (`pTest')
								
				post welfareTable ///
					(`aGse') ("") (`aLse') ("") ///
					(`seBg') ("") (`seBl') ("") ///
					(`alphaSE') ("") (`alphaMaxSE') ("") ("") (.)
				
				
			}
			postclose welfareTable
			
			// Format the table (Supplementary Table B.2.B)
			preserve
				clear
				use "data/welfareTable.dta"
								
				gen c1 = "("
				replace c1 = "" if mod(_n,2) == 1
				
				gen c2 = ") & ("
				replace c2 = "  &  " if mod(_n,2) == 1
				
				gen c3 = c2
				gen c4 = c2
				gen c5 = c2
				gen c6 = c2
				
				gen c7 = ") & "
				replace c7 = "  &  " if mod(_n,2) == 1
				
				gen c8 = " & " 
				
				gen c9 = " \\ "
				
				order c1 aG starsGainA c2 /// 
						 aL starsLossA c3 ///
						 alphaMax starsAlphaMax c6 ///
						 bG starsGain  c4 /// 
						 bL starsLoss  c5 /// 
						 alphaMin starsAlpha c7 ///
						 cond c8 p c9
				
				
				// Input format of the table
				
				
				/*
				Condition
				Delay
				Noncompensable
				80%
				50%
				20%
				Compensable 
				80%
				50%
				20%

				Contemporaneous
				Noncompensable
				80%
				50%
				20%
				Compensable 
				80%
				50%
				20%
				*/
				
				
				
				
				gen line = (_n+1)/2
				
				gen newline = .
				replace newline = line - 9 	if line >= 10
				replace newline = line   	if line >= 4 & line < 7
				replace newline = line   	if line >= 7 & line < 10
				replace newline = line + 9 	if line < 4

				
				replace line = newline 
				sort line 
				drop line newline
				
				
				gen rowlabel = "&"
				replace rowlabel = "\qquad 20\% & " if mod(_n, 6) == 1
				replace rowlabel = "\qquad 50\% & " if mod(_n, 6) == 3
				replace rowlabel = "\qquad 80\% & " if mod(_n, 6) == 5
				
				local lines = _N
				local newLines = `lines' + 6
				di `newLines'
				set obs `newLines'
				
				
				replace rowlabel = "Limited Loss \\" 				if _n == 25
				replace rowlabel = "\quad Contemporaneous \\ \qquad Prior success probability\\" 	if _n == 26
				replace rowlabel = "\quad Delayed \\ \qquad Prior success probability\\" 		if _n == 27
				replace rowlabel = "Large Loss \\" 	if _n == 28
				replace rowlabel = "\quad Contemporaneous \\ \qquad Prior success probability\\" 	if _n == 29
				replace rowlabel = "\quad Delayed \\ \qquad Prior success probability\\" 		if _n == 30
				
				
				gen location = _n
				replace location = 0 		if location == 25
				replace location = 0.5 		if location == 26
				replace location = 6.5 		if location == 27
				replace location = 12.5 	if location == 28
				replace location = 12.6 	if location == 29
				replace location = 18.5 	if location == 30
				
				sort location
				drop location
				order rowlabel
				
				
				format aG aL bG bL alphaMin alphaMax p %9.3f
				export delimited using "../writeup/tables/SupplementaryTableB2B.tsv", delimiter(tab)  datafmt novar replace
								
			restore		
		}
		
		// Welfare table Ridge (Supplementary Table B.3.B)
		if 1 {
			cap drop gain  
			cap drop loss
			
			cap gen betCElasso = bet * minCElasso
			gen gain = max(betCElasso, 0)
			gen loss = min(betCElasso, 0)

			cap drop winMin
			gen winMin = win - 1
			replace winMin = . if win == 0
			
			set seed 1
			
			mysureg (gain winMin) /// 
					(loss winMin) ///
					if known == 1 & catastrophe == 0 ///
					, vce(cluster id)

			local mMin = 0
			noisily: nlcom   (eq1:(([gain]_cons + `mMin'*[gain]win) / (([gain]_cons + `mMin'*[gain]win) - ([loss]_cons +  `mMin'*[loss]win))) ///
					- ([gain]win / ([gain]win - [loss]win))) ///
					(eq2:([gain]win / ([gain]win - [loss]win))) ///						
					, post
			

			mysureg (gain winMin) /// 
					(loss winMin) ///
					if known == 1 & catastrophe == 1 ///
					, vce(cluster id)			
			
			set seed 1
			
			
					
			mysureg (gain winMin) /// 
					(loss winMin) ///
					if known == 1 ///
					, vce(cluster id)

			local mMin = 0
			noisily: nlcom   (eq1:(([gain]_cons + `mMin'*[gain]win) / (([gain]_cons + `mMin'*[gain]win) - ([loss]_cons +  `mMin'*[loss]win))) ///
					- ([gain]win / ([gain]win - [loss]win))) ///
					(eq2:([gain]win / ([gain]win - [loss]win))) ///						
					, post
					

					
					
			mysureg (gain winMin) /// 
					(loss winMin) ///
					if known == 0 ///
					, vce(cluster id)

			
			local mMin = 0
			nlcom   (eq1:(([gain]_cons + `mMin'*[gain]win) / (([gain]_cons + `mMin'*[gain]win) - ([loss]_cons +  `mMin'*[loss]win))) ///
					- ([gain]win / ([gain]win - [loss]win))) ///
					(eq2:([gain]win / ([gain]win - [loss]win))) ///						
					, post		

		
			cap postclose welfareTable
			postfile welfareTable ///
					 aG str3 starsGainA double aL str3 starsLossA ///
					 bG str3 starsGain double bL str3 starsLoss ///
					 double alphaMin str4 starsAlpha ///
					 double alphaMax str4 starsAlphaMax ///
					 str4 cond double p ///
					 using "data/welfareTableLasso.dta", replace
			
			foreach cond2 of numlist 1/6 13/18 {
				preserve 
					
					keep if known == 1
					keep if cond2 == `cond2'
					set seed 1
					
					mysureg (gain win) /// 
							(loss win) ///
						, vce(cluster id)
				
				
				
				
				
					
					local mMin = 1
					local mMax = 5
					
					// Condition
					nlcom   (eq1:(([gain]_cons + `mMin'*[gain]win) / (([gain]_cons + `mMin'*[gain]win) - ([loss]_cons +  `mMin'*[loss]win))) ///
							- ([gain]_cons + `mMax'*[gain]win) / (([gain]_cons + `mMax'*[gain]win) - ([loss]_cons +  `mMax'*[loss]win))) ///
							(eq2: (([gain]_cons + `mMax'*[gain]win) / (([gain]_cons + `mMax'*[gain]win) - ([loss]_cons +  `mMax'*[loss]win)))) ///	
							(eq3: ([gain]_cons + `mMin'*[gain]win)) ///
							(eq4: ([loss]_cons + `mMin'*[loss]win)) ///
							(eq5: (([gain]_cons + `mMin'*[gain]win) / (([gain]_cons + `mMin'*[gain]win) - ([loss]_cons +  `mMin'*[loss]win)))) ///
							(eq6: ([gain]_cons + `mMax'*[gain]win)) ///
							(eq7: ([loss]_cons + `mMax'*[loss]win)) ///
						, post
					
					// New
					
					
					local bG = _b[eq6]
					local bL = _b[eq7]
					local seBg = _se[eq6] 
					local seBl = _se[eq7]
					
					test eq6 == 0
					local pGain = r(p)
					test eq7 == 0
					local pLoss = r(p)
					
					
					local starsGain = ""
					if (`pGain' <= 0.01) {
						local starsGain = "***"
					}
					if (`pGain' <= 0.05 & `pGain'>0.01) {
						local starsGain = "**"
					}
					if (`pGain' < 0.1 & `pGain'>0.05) {
						local starsGain = "*"
					}
					
					
					local starsLoss = ""
					if (`pLoss' <= 0.01) {
						local starsLoss = "***"
					}
					if (`pLoss' <= 0.05 & `pLoss'>0.01) {
						local starsLoss = "**"
					}
					if (`pLoss' < 0.1 & `pLoss'>0.05) {
						local starsLoss = "*"
					}
					
					
					
					
					// Previous
					
					local alphaMin = _b[eq2]
					local alphaSE = _se[eq2]
					local alphaMax = _b[eq5]
					local alphaMaxSE = _se[eq5]
					
					test eq2 == 0
					local pAlpha = r(p)
					
					local starsAlpha = ""
					if (`pAlpha' <= 0.01) {
						local starsAlpha = "***"
					}
					if (`pAlpha' <= 0.05 & `pAlpha'>0.01) {
						local starsAlpha = "**"
					}
					if (`pAlpha' < 0.1 & `pAlpha'>0.05) {
						local starsAlpha = "*"
					}

					local possibilityCond = "No"
					if (_b[eq1] >= 0) {
						local possibilityCond = "Yes"
					}
					
					
					test eq5 == 1
					local pAlphaMax = r(p)
					
					local starsAlphaMax = ""
					if (`pAlphaMax' <= 0.01) {
						local starsAlphaMax = "***"
					}
					if (`pAlphaMax' <= 0.05 & `pAlpha'>0.01) {
						local starsAlphaMax = "**"
					}
					if (`pAlphaMax' < 0.1 & `pAlpha'>0.05) {
						local starsAlphaMax = "*"
					}

					local possibilityCond = "No"
					if (_b[eq1] >= 0) {
						local possibilityCond = "Yes"
					}
					
					
					local aG = _b[eq3]
					local aGse = _se[eq3]
					local aL = _b[eq4]
					local aLse = _se[eq4]
					
					
					
					test _b[eq3] == 0
					local pGainA = r(p)
					test _b[eq4] == 0
					local pLossA = r(p)
					
					
					local starsGainA = ""
					if (`pGainA' <= 0.01) {
						local starsGainA = "***"
					}
					if (`pGainA' <= 0.05 & `pGainA'>0.01) {
						local starsGainA = "**"
					}
					if (`pGainA' < 0.1 & `pGainA'>0.05) {
						local starsGainA = "*"
					}
					
					
					local starsLossA = ""
					if (`pLossA' <= 0.01) {
						local starsLossA = "***"
					}
					if (`pLossA' <= 0.05 & `pLossA'>0.01) {
						local starsLossA = "**"
					}
					if (`pLossA' < 0.1 & `pLossA'>0.05) {
						local starsLossA = "*"
					}
					
					
					noisily: di "`possibilityCond'"
							
					test eq1
					local pTest = r(p)

					
				restore
				post welfareTable ///
					(`aG') ("`starsGainA'") (`aL') ("`starsLossA'")  ///
					(`bG') ("`starsGain'") (`bL') ("`starsLoss'") ///
					(`alphaMin') ("`starsAlpha'") (`alphaMax') ("`starsAlphaMax'") ///
					("`possibilityCond'") (`pTest')
								
				post welfareTable ///
					(`aGse') ("") (`aLse') ("") ///
					(`seBg') ("") (`seBl') ("") ///
					(`alphaSE') ("") (`alphaMaxSE') ("") ("") (.)
				
				
			}
			postclose welfareTable
			
			// Format the table (Supplementary Table B.3.B)
			preserve
				clear
				use "data/welfareTableLasso.dta"
								
				gen c1 = "("
				replace c1 = "" if mod(_n,2) == 1
				
				gen c2 = ") & ("
				replace c2 = "  &  " if mod(_n,2) == 1
				
				gen c3 = c2
				gen c4 = c2
				gen c5 = c2
				gen c6 = c2
				
				gen c7 = ") & "
				replace c7 = "  &  " if mod(_n,2) == 1
				
				gen c8 = " & " 
				
				gen c9 = " \\ "
				
				order c1 aG starsGainA c2 /// 
						 aL starsLossA c3 ///
						 alphaMax starsAlphaMax c6 ///
						 bG starsGain  c4 /// 
						 bL starsLoss  c5 /// 
						 alphaMin starsAlpha c7 ///
						 cond c8 p c9
				
				
				// Input format of the table
				
				
				/*
				Condition
				Delay
				Noncompensable
				80%
				50%
				20%
				Compensable 
				80%
				50%
				20%

				Contemporaneous
				Noncompensable
				80%
				50%
				20%
				Compensable 
				80%
				50%
				20%
				*/
				
				
				
				
				gen line = (_n+1)/2
				
				gen newline = .
				replace newline = line - 9 	if line >= 10
				replace newline = line   	if line >= 4 & line < 7
				replace newline = line   	if line >= 7 & line < 10
				replace newline = line + 9 	if line < 4

				
				replace line = newline 
				sort line 
				drop line newline
				
				
				gen rowlabel = "&"
				replace rowlabel = "\qquad 20\% & " if mod(_n, 6) == 1
				replace rowlabel = "\qquad 50\% & " if mod(_n, 6) == 3
				replace rowlabel = "\qquad 80\% & " if mod(_n, 6) == 5
				
				local lines = _N
				local newLines = `lines' + 6
				di `newLines'
				set obs `newLines'
				
				
				replace rowlabel = "Limited Loss \\" 				if _n == 25
				replace rowlabel = "\quad Contemporaneous \\ \qquad Prior success probability\\" 	if _n == 26
				replace rowlabel = "\quad Delayed \\ \qquad Prior success probability\\" 		if _n == 27
				replace rowlabel = "Large Loss \\" 	if _n == 28
				replace rowlabel = "\quad Contemporaneous \\ \qquad Prior success probability\\" 	if _n == 29
				replace rowlabel = "\quad Delayed \\ \qquad Prior success probability\\" 		if _n == 30
				
				
				gen location = _n
				replace location = 0 		if location == 25
				replace location = 0.5 		if location == 26
				replace location = 6.5 		if location == 27
				replace location = 12.5 	if location == 28
				replace location = 12.6 	if location == 29
				replace location = 18.5 	if location == 30
				
				sort location
				drop location
				order rowlabel
				
				
				format aG aL bG bL alphaMin alphaMax p %9.3f
				export delimited using "../writeup/tables/SupplementaryTableB3B.tsv", delimiter(tab)  datafmt novar replace
								
			restore		
		}
		
		// Welfare table linear gains / losses ex-post benchmark (Supplementary Table B.4.B)
		if 1 {
			
			
			
			cap drop gainPat
			cap drop lossPat
			gen gainPat = bet*win*state
			gen lossPat = bet*(win - 6)*(1-state)
			replace lossPat = bet*(- 6)*(1-state) if catastropheTreatment == 1
			
			
			cap drop winMin
			gen winMin = win - 1
			replace winMin = . if win == 0
			
			set seed 1
			
			mysureg (gainPat winMin) /// 
					(lossPat winMin) ///
					if known == 1 & catastrophe == 0 ///
					, vce(cluster id)

			local mMin = 0
			noisily: nlcom   (eq1:(([gainPat]_cons + `mMin'*[gainPat]win) / (([gainPat]_cons + `mMin'*[gainPat]win) - ([lossPat]_cons +  `mMin'*[lossPat]win))) ///
					- ([gainPat]win / ([gainPat]win - [lossPat]win))) ///
					(eq2:([gainPat]win / ([gainPat]win - [lossPat]win))) ///						
					, post
			

			mysureg (gainPat winMin) /// 
					(lossPat winMin) ///
					if known == 1 & catastrophe == 1 ///
					, vce(cluster id)			
			
			set seed 1
			
			
					
			mysureg (gainPat winMin) /// 
					(lossPat winMin) ///
					if known == 1 ///
					, vce(cluster id)

			local mMin = 0
			noisily: nlcom   (eq1:(([gainPat]_cons + `mMin'*[gainPat]win) / (([gainPat]_cons + `mMin'*[gainPat]win) - ([lossPat]_cons +  `mMin'*[lossPat]win))) ///
					- ([gainPat]win / ([gainPat]win - [lossPat]win))) ///
					(eq2:([gainPat]win / ([gainPat]win - [lossPat]win))) ///						
					, post
					

					
					
			mysureg (gainPat winMin) /// 
					(lossPat winMin) ///
					if known == 0 ///
					, vce(cluster id)

			
			local mMin = 0
			nlcom   (eq1:(([gainPat]_cons + `mMin'*[gainPat]win) / (([gainPat]_cons + `mMin'*[gainPat]win) - ([lossPat]_cons +  `mMin'*[lossPat]win))) ///
					- ([gainPat]win / ([gainPat]win - [lossPat]win))) ///
					(eq2:([gainPat]win / ([gainPat]win - [lossPat]win))) ///						
					, post		

		
			cap postclose welfareTable
			postfile welfareTable ///
					 aG str3 starsgainPatA double aL str3 starslossPatA ///
					 bG str3 starsgainPat double bL str3 starslossPat ///
					 double alphaMin str4 starsAlpha ///
					 double alphaMax str4 starsAlphaMax ///
					 str4 cond double p ///
					 using "data/welfareTable.dta", replace
			
			foreach cond2 of numlist 1/6 13/18 {
				preserve 
					
					keep if known == 1
					keep if cond2 == `cond2'
					set seed 1
					
					mysureg (gainPat win) /// 
							(lossPat win) ///
						, vce(cluster id)
				
				
				
				
				
					
					local mMin = 1
					local mMax = 5
					
					// Condition
					nlcom   (eq1:(([gainPat]_cons + `mMin'*[gainPat]win) / (([gainPat]_cons + `mMin'*[gainPat]win) - ([lossPat]_cons +  `mMin'*[lossPat]win))) ///
							- ([gainPat]_cons + `mMax'*[gainPat]win) / (([gainPat]_cons + `mMax'*[gainPat]win) - ([lossPat]_cons +  `mMax'*[lossPat]win))) ///
							(eq2: (([gainPat]_cons + `mMax'*[gainPat]win) / (([gainPat]_cons + `mMax'*[gainPat]win) - ([lossPat]_cons +  `mMax'*[lossPat]win)))) ///	
							(eq3: ([gainPat]_cons + `mMin'*[gainPat]win)) ///
							(eq4: ([lossPat]_cons + `mMin'*[lossPat]win)) ///
							(eq5: (([gainPat]_cons + `mMin'*[gainPat]win) / (([gainPat]_cons + `mMin'*[gainPat]win) - ([lossPat]_cons +  `mMin'*[lossPat]win)))) ///
							(eq6: ([gainPat]_cons + `mMax'*[gainPat]win)) ///
							(eq7: ([lossPat]_cons + `mMax'*[lossPat]win)) ///
						, post
					
					// New
					
					
					local bG = _b[eq6]
					local bL = _b[eq7]
					local seBg = _se[eq6] 
					local seBl = _se[eq7]
					
					test eq6 == 0
					local pgainPat = r(p)
					test eq7 == 0
					local plossPat = r(p)
					
					
					local starsgainPat = ""
					if (`pgainPat' <= 0.01) {
						local starsgainPat = "***"
					}
					if (`pgainPat' <= 0.05 & `pgainPat'>0.01) {
						local starsgainPat = "**"
					}
					if (`pgainPat' < 0.1 & `pgainPat'>0.05) {
						local starsgainPat = "*"
					}
					
					
					local starslossPat = ""
					if (`plossPat' <= 0.01) {
						local starslossPat = "***"
					}
					if (`plossPat' <= 0.05 & `plossPat'>0.01) {
						local starslossPat = "**"
					}
					if (`plossPat' < 0.1 & `plossPat'>0.05) {
						local starslossPat = "*"
					}
					
					
					
					
					// Previous
					
					local alphaMin = _b[eq2]
					local alphaSE = _se[eq2]
					local alphaMax = _b[eq5]
					local alphaMaxSE = _se[eq5]
					
					test eq2 == 0
					local pAlpha = r(p)
					
					local starsAlpha = ""
					if (`pAlpha' <= 0.01) {
						local starsAlpha = "***"
					}
					if (`pAlpha' <= 0.05 & `pAlpha'>0.01) {
						local starsAlpha = "**"
					}
					if (`pAlpha' < 0.1 & `pAlpha'>0.05) {
						local starsAlpha = "*"
					}

					local possibilityCond = "No"
					if (_b[eq1] >= 0) {
						local possibilityCond = "Yes"
					}
					
					
					test eq5 == 1
					local pAlphaMax = r(p)
					
					local starsAlphaMax = ""
					if (`pAlphaMax' <= 0.01) {
						local starsAlphaMax = "***"
					}
					if (`pAlphaMax' <= 0.05 & `pAlpha'>0.01) {
						local starsAlphaMax = "**"
					}
					if (`pAlphaMax' < 0.1 & `pAlpha'>0.05) {
						local starsAlphaMax = "*"
					}

					local possibilityCond = "No"
					if (_b[eq1] >= 0) {
						local possibilityCond = "Yes"
					}
					
					
					local aG = _b[eq3]
					local aGse = _se[eq3]
					local aL = _b[eq4]
					local aLse = _se[eq4]
					
					
					
					test _b[eq3] == 0
					local pgainPatA = r(p)
					test _b[eq4] == 0
					local plossPatA = r(p)
					
					
					local starsgainPatA = ""
					if (`pgainPatA' <= 0.01) {
						local starsgainPatA = "***"
					}
					if (`pgainPatA' <= 0.05 & `pgainPatA'>0.01) {
						local starsgainPatA = "**"
					}
					if (`pgainPatA' < 0.1 & `pgainPatA'>0.05) {
						local starsgainPatA = "*"
					}
					
					
					local starslossPatA = ""
					if (`plossPatA' <= 0.01) {
						local starslossPatA = "***"
					}
					if (`plossPatA' <= 0.05 & `plossPatA'>0.01) {
						local starslossPatA = "**"
					}
					if (`plossPatA' < 0.1 & `plossPatA'>0.05) {
						local starslossPatA = "*"
					}
					
					
					noisily: di "`possibilityCond'"
							
					test eq1
					local pTest = r(p)

					
				restore
				post welfareTable ///
					(`aG') ("`starsgainPatA'") (`aL') ("`starslossPatA'")  ///
					(`bG') ("`starsgainPat'") (`bL') ("`starslossPat'") ///
					(`alphaMin') ("`starsAlpha'") (`alphaMax') ("`starsAlphaMax'") ///
					("`possibilityCond'") (`pTest')
								
				post welfareTable ///
					(`aGse') ("") (`aLse') ("") ///
					(`seBg') ("") (`seBl') ("") ///
					(`alphaSE') ("") (`alphaMaxSE') ("") ("") (.)
				
				
			}
			postclose welfareTable
			
			// Format the table (Supplementary Table B.4.B)
			preserve
				clear
				use "data/welfareTable.dta"
								
				gen c1 = "("
				replace c1 = "" if mod(_n,2) == 1
				
				gen c2 = ") & ("
				replace c2 = "  &  " if mod(_n,2) == 1
				
				gen c3 = c2
				gen c4 = c2
				gen c5 = c2
				gen c6 = c2
				
				gen c7 = ") & "
				replace c7 = "  &  " if mod(_n,2) == 1
				
				gen c8 = " & " 
				
				gen c9 = " \\ "
				
				order c1 aG starsgainPatA c2 /// 
						 aL starslossPatA c3 ///
						 alphaMax starsAlphaMax c6 ///
						 bG starsgainPat  c4 /// 
						 bL starslossPat  c5 /// 
						 alphaMin starsAlpha c7 ///
						 cond c8 p c9
				
				
				// Input format of the table
				
				
				/*
				Condition
				Delay
				Noncompensable
				80%
				50%
				20%
				Compensable 
				80%
				50%
				20%

				Contemporaneous
				Noncompensable
				80%
				50%
				20%
				Compensable 
				80%
				50%
				20%
				*/
				
				
				
				
				gen line = (_n+1)/2
				
				gen newline = .
				replace newline = line - 9 	if line >= 10
				replace newline = line   	if line >= 4 & line < 7
				replace newline = line   	if line >= 7 & line < 10
				replace newline = line + 9 	if line < 4

				
				replace line = newline 
				sort line 
				drop line newline
				
				
				gen rowlabel = "&"
				replace rowlabel = "\qquad 20\% & " if mod(_n, 6) == 1
				replace rowlabel = "\qquad 50\% & " if mod(_n, 6) == 3
				replace rowlabel = "\qquad 80\% & " if mod(_n, 6) == 5
				
				local lines = _N
				local newLines = `lines' + 6
				di `newLines'
				set obs `newLines'
				
				replace rowlabel = "Limited Loss \\" 				if _n == 25
				replace rowlabel = "\quad Contemporaneous \\ \qquad Prior success probability\\" 	if _n == 26
				replace rowlabel = "\quad Delayed \\ \qquad Prior success probability\\" 		if _n == 27
				replace rowlabel = "Large Loss \\" 	if _n == 28
				replace rowlabel = "\quad Contemporaneous \\ \qquad Prior success probability\\" 	if _n == 29
				replace rowlabel = "\quad Delayed \\ \qquad Prior success probability\\" 		if _n == 30
				
				
				gen location = _n
				replace location = 0 		if location == 25
				replace location = 0.5 		if location == 26
				replace location = 6.5 		if location == 27
				replace location = 12.5 	if location == 28
				replace location = 12.6 	if location == 29
				replace location = 18.5 	if location == 30
				
				sort location
				drop location
				order rowlabel
				
				
				format aG aL bG bL alphaMin alphaMax p %9.3f
				export delimited using "../writeup/tables/SupplementaryTableB4B.tsv", delimiter(tab)  datafmt novar replace
								
			restore		
		}
		
	}	

	
}


// Figures 
if 1 {	
	// Supplementary Figure B.1.B: Information choice
	if 1 {
		preserve 
		
			keep if delayTr == 0
			keep if prior == "mid"
			
			keep if win > 0
			replace win = 2 if win <= 2
			replace win = 4 if win >= 4
			
			cap gen win2k 	= win <= 2 & known == 1
			cap gen win10k 	= win >= 4 & known == 1

			cap gen win2u 	= win <= 2 & known == 0
			cap gen win10u 	= win >= 4 & known == 0
		
			reg infoStr win*k win*u, nocons cl(id)
			local s2k = _se[win2k]
			local s10k = _se[win10k]
			local s2u = _se[win2u]
			local s10u = _se[win10u]
			
			local aspect = 0.75
			collapse infoStr highInc, by(win known)
			
			gen se = .
			replace se = `s2k' if win <= 2 & known == 1
			replace se = `s10k' if win >= 4 & known == 1
			
			replace se = `s2u' if win <= 2 & known == 0
			replace se = `s10u' if win >= 4 & known == 0
			
			gen upper = infoStr + 1.96*se
			gen lower = infoStr - 1.96*se
			
			replace win = win + 0.02 if known == 1
			replace win = win - 0.02 if known == 0
			
			// Customize graph scheme
			grstyle init
			grstyle set graphsize 64mm 88mm
			grstyle set margin "5mm 5mm 2.5mm 2.5mm": graph
			
			tw 	(line infoStr win 		if known == 1, lcolor(navy) 	lpattern(solid) 	lwidth(0.75)) ///
				(line infoStr win 		if known == 0, lcolor(maroon) 	lpattern(longdash)	lwidth(0.75)) ///
				(rcap upper lower win 	if known == 1, lcolor(navy)) ///
				(rcap upper lower win 	if known == 0, lcolor(maroon)) ///
				, name(gr1, replace) ///
				ylabel(0(0.2)0.6, angle(90)) ytitle("Frequency bold advisor chosen") ///
				xtitle("Incentive amount") legend(order(1 "Incentive First" 2 "Advisor Choice First")  ring(0) col(1) pos(5) region(lc(black))) ///
				bgcolor(white) graphregion(color(white)) ///
				xlabel(2 "{&le} €2" 4 "{&ge} €4" ) ///
				xscale(range(1.5 4.5)) ///
				scale(1.3)
			graph export "../writeup/graphs/SupplementaryFigureB1B.pdf", replace
			export excel "../writeup/sourceDataFigures/sourceData_SupplementaryFigureB1.xlsx", firstrow(variables) sheet("FigureB1B", modify)
			
			
			// Clear customized graph scheme
			grstyle clear
			
		restore
	}
		
	// Supplementary Figure: Supply NOT USED
	if 1 {
		

		preserve 
			
			keep if win > 0 
			
			cap gen win1k 	= win == 1	& known == 1
			cap gen win2k 	= win == 2	& known == 1
			cap gen win10k 	= win == 4 & known == 1
			cap gen win11k 	= win == 5 & known == 1

			cap gen win1u 	= win == 1	& known == 0
			cap gen win2u 	= win == 2	& known == 0
			cap gen win10u 	= win == 4 & known == 0
			cap gen win11u 	= win == 5 & known == 0
		
			reg bet win*k win*u, nocons cl(id)
			local s1k = _se[win1k]
			local s2k = _se[win1k]
			local s10k = _se[win10k]
			local s11k = _se[win11k]
			local s1u = _se[win1u]
			local s2u = _se[win1u]
			local s10u = _se[win10u]
			local s11u = _se[win11u]
			
			local aspect = 0.75
			collapse bet highInc  [pw = weight], by(win known)
			
			gen se = .
			replace se = `s1k' if win == 1 & known == 1
			replace se = `s2k' if win == 2 & known == 1
			replace se = `s10k' if win == 4 & known == 1
			replace se = `s11k' if win == 5 & known == 1
			
			replace se = `s1u' if win == 1 & known == 0
			replace se = `s2u' if win == 2 & known == 0
			replace se = `s10u' if win == 4 & known == 0
			replace se = `s11u' if win == 5 & known == 0
			
			gen upper = bet + 1.96*se
			gen lower = bet - 1.96*se
			
			// Customize graph scheme
			grstyle init
			grstyle set graphsize 64mm 88mm
			grstyle set margin "5mm 5mm 2.5mm 2.5mm": graph
			
			tw 	(line bet win 		if known == 1, lcolor(navy) 	lpattern(solid) 	lwidth(0.75)) ///
				(line bet win 		if known == 0, lcolor(maroon) 	lpattern(longdash)	lwidth(0.75)) ///
				(rcap upper lower win if known == 1, lcolor(navy)) ///
				(rcap upper lower win if known == 0, lcolor(maroon)) ///
				, name(gr1, replace) ///
				ylabel(0.2(0.1)0.6, angle(90)) ytitle("Frequency participated in venture") ///
				xtitle("Incentive amount") legend(order(1 "Incentive First" 2 "Advisor Choice First")  ring(0) col(1) pos(10) region(lc(black))) ///
				bgcolor(white) graphregion(color(white)) ///
				xlabel(1 2 4 5) ///
				xscale(range(0 6)) ///
				scale(1.3)
			graph export "../writeup/graphs/exp2extSupply.pdf", replace
			
			// Clear customized graph scheme
			grstyle clear
			
		restore	
		
	}
		
	// Supplementary Figure B.1.F: CDF welfare
	if 1 {
		
		// NOT USED
		preserve

			cap cumul betCE if known == 1 & highInc == 1 [aw = weight], gen(diffHighTr)
			cap cumul betCE if known == 1 & highInc == 0 [aw = weight], gen(diffLowTr)
			
			sort diffHighTr diffLowTr 
			
			// Customize graph scheme
			grstyle init
			grstyle set graphsize 64mm 88mm
			grstyle set margin "5mm 5mm 2.5mm 2.5mm": graph
						
			tw	(line diffHighTr betCE, lwidth(0.5) lcolor(navy) 	lpattern(solid)) ///
				(line diffLowTr  betCE, lwidth(0.5) lcolor(maroon) 	lpattern(shortdash)) ///
				, ///
				xtitle("Ex-ante surplus in {c 0128}") ///
				xscale(range(-6 6)) ///
				xlabel(-6(6)6) /// 
				ytitle("Cumulative frequency") ///
				ylabel(, angle(90)) ///
				legend(order(1 "Incentive {&ge} {c 0128} 4" 2 "Incentive {&le} {c 0128} 2") ring(0) col(1) pos(10) region(lc(black))) ///		
				xline(0, lcolor(black) lpattern(solid) lwidth(0.25)) ///
				bgcolor(white) graphregion(color(white)) ///
				scale(1.3)
			graph export "../writeup/graphs/welfareCDFsimplePooled.pdf", replace
			
			// Clear customized graph scheme
			grstyle clear
			
		restore

		// USED
		preserve

			keep if delayTr == 0
			keep if prior == "mid"
			
			cap cumul betCE if known == 1 & highInc == 1 [aw = weight], gen(diffHighTr)
			cap cumul betCE if known == 1 & highInc == 0 [aw = weight], gen(diffLowTr)
			
			sort diffHighTr diffLowTr 

			// Customize graph scheme
			grstyle init
			grstyle set graphsize 64mm 88mm
			grstyle set margin "5mm 5mm 2.5mm 2.5mm": graph		
			
			tw	(line diffHighTr betCE, lwidth(0.5) lcolor(navy) 	lpattern(solid)) ///
				(line diffLowTr  betCE, lwidth(0.5) lcolor(maroon) 	lpattern(shortdash)) ///
				, ///
				xtitle("Ex-ante surplus in {c 0128}") ///
				xscale(range(-6 6)) ///
				xlabel(-6(6)6) /// 
				ytitle("Cumulative frequency") ///
				ylabel(, angle(90)) ///
				legend(order(1 "Incentive {&ge} {c 0128} 4" 2 "Incentive {&le} {c 0128} 2") ring(0) col(1) pos(10) region(lc(black))) ///		
				xline(0, lcolor(black) lpattern(solid) lwidth(0.25)) ///
				bgcolor(white) graphregion(color(white)) ///
				scale(1.3)
			graph export "../writeup/graphs/SupplementaryFigureB1F.pdf", replace
			keep diffHighTr diffLowTr betCE
			export excel "../writeup/sourceDataFigures/sourceData_SupplementaryFigureB1.xlsx", firstrow(variables) sheet("FigureB1F", modify)
			
			// Clear customized graph scheme
			grstyle clear
			
		restore
		
	}

	// Supplementary Figure B.1.D: Beliefs
	if 1 {


		gen trIndex = catastropheTr + 10*delayTr + 100*(10*priorNum)
		
		// This used in text:
		reg belief highInc catastropheTr delayTr priorNum	 	if known == 1, cl(id)

		reg belief highInc known win_known				 , cl(id)
		reg belief highInc known win_known i.trIndex	 , cl(id)


		preserve
		
			keep if delayTr == 0
			keep if prior == "mid"
			
			keep if known == 1
			
			cumul belief if highInc == 0, gen(cumBel0)
			cumul belief if highInc == 1, gen(cumBel1)
			sort  cumBel0 cumBel1 belief
			
			// Customize graph scheme
			grstyle init
			grstyle set graphsize 88mm 88mm
			grstyle set margin "2.5mm 2.5mm 2.5mm 2.5mm": graph

			tw	(line cumBel0 belief if highInc == 0, lcolor(navy)) ///
				(line cumBel1 belief if highInc == 1, lcolor(maroon)) ///
				, ///
				xlabel(0 0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95 1) ///
				ylab(0(0.2)1, nogrid angle(90)) ///
				ytitle("Cumulative frequency") ///
				xtitle("Subjective belief P(s=G)") ///
				ysize(2) xsize(2) ///
				plotregion(margin(zero)) ///
				legend(order(1 "Incentive {&le} {c 0128}2" 2 "Incentive {&ge} {c 0128}4") col(1) ring(0) pos(11) region(lc(black))) ///
				aspect(1) bgcolor(white) graphregion(color(white)) ///
				scale(1.2)
			graph export "../writeup/graphs/SupplementaryFigureB1D.pdf", replace
			keep cumBel0 cumBel1 belief highInc
			export excel "../writeup/sourceDataFigures/sourceData_SupplementaryFigureB1.xlsx", firstrow(variables) sheet("FigureB1D", modify)

			// Clear customized graph scheme
			grstyle clear
				
		restore

			
		
	}


}		

	
// As presented in paper
if 1 {
	// Data mentioned in main text
	if 1 {
   
			// Table number of participants
			if 1 {
					gen priorFailureNum = 1 - priorNum
					tab delay priorFailureNum if tag == 1, chi2
			}
   
			// Information choice summary statistics
			if 1 {
					su infoStr if win == 1 & known == 1
					su infoStr if win == 5 & known == 1
					su infoStr if known == 0
				   
					reg infoStr win if known == 1, cl(id)
					reg infoStr win i.cond2 if known == 1, cl(id)

					reg infoStr win known win_known i.cond2, cl(id)
					
					reg infoStr highInc known highInc_known, cl(id)
				   
			}
		   
			// Multiple switching summary statistics
			if 1 {
					su multipleS

					gen numRoundsMultiSw = 26 * fracMultiSw
				   
					su numRoundsMultiSw, d
				   
					su numRoundsMultiSw if delay == 0, d
					su numRoundsMultiSw if delay == 1, d
					su everMultiSw if delay == 0, d
					su everMultiSw if delay == 1, d
				   
					reg numRoundsMultiSw delayTr if tag == 1
								   
			}
		   
			// Information choice summary statistics
			if 1 {
					reg infoStr known win win_known , cl(id)
			}
		   
			// Information choice by prior
			if 1 {
					su infoStr if known == 0 & prior == "low" & win ~= 0
					su infoStr if known == 0 & prior == "mid" & win ~= 0
					su infoStr if known == 0 & prior == "high" & win ~= 0
				   
					// xi: reg infoStr i.priorNum  if known == 0, cl(id)
					// test _IpriorNum_2 = _IpriorNum3
				   
				   
			}
		   
			// Supply summary statistics
			if 1 {
		   
					su bet if win == 5 & known == 0
					local supplyUnknown = r(mean)
					su bet if win == 5 & known == 1
					local supplyKnown = r(mean)
					local diff = `supplyKnown' - `supplyUnknown'
					di `diff'
				   
					reg bet known win win_known, cl(id)
			}
		   
			// Testing instrumentality of information in Advisor Choice First condition
			if 1 {
				   
					su bet if known == 0 & highInc == 0 & infoStr == 0 & signal == 0
					su bet if known == 0 & highInc == 0 & infoStr == 0 & signal == 1
					su bet if known == 0 & highInc == 1 & infoStr == 0 & signal == 0
					su bet if known == 0 & highInc == 1 & infoStr == 0 & signal == 1

					su bet if known == 0 & highInc == 0 & infoStr == 1 & signal == 0
					su bet if known == 0 & highInc == 0 & infoStr == 1 & signal == 1
					su bet if known == 0 & highInc == 1 & infoStr == 1 & signal == 0
					su bet if known == 0 & highInc == 1 & infoStr == 1 & signal == 1

					su bet if known == 0 & win == 1 & infoStr == 0 & signal == 0
					su bet if known == 0 & win == 1 & infoStr == 0 & signal == 1
					su bet if known == 0 & win == 5 & infoStr == 0 & signal == 0
					su bet if known == 0 & win == 5 & infoStr == 0 & signal == 1

					su bet if known == 0 & win == 1 & infoStr == 1 & signal == 0
					su bet if known == 0 & win == 1 & infoStr == 1 & signal == 1
					su bet if known == 0 & win == 5 & infoStr == 1 & signal == 0
					su bet if known == 0 & win == 5 & infoStr == 1 & signal == 1
				   
				   
					reg bet signal if known == 0 & win == 1 & infoStr == 0
					reg bet signal if known == 0 & win == 1 & infoStr == 1
					reg bet signal if known == 0 & win == 2 & infoStr == 0
					reg bet signal if known == 0 & win == 2 & infoStr == 1
					reg bet signal if known == 0 & win == 4 & infoStr == 0
					reg bet signal if known == 0 & win == 4 & infoStr == 1
					reg bet signal if known == 0 & win == 5 & infoStr == 0
					reg bet signal if known == 0 & win == 5 & infoStr == 1
				   
				   
			}
		   
			// Welfare
			if 1 {
				   
					su gain if known == 1 & win == 1
					su loss if known == 1 & win == 1
					su gain if known == 1 & win == 2
					su loss if known == 1 & win == 2
				   
					reg gain win if known == 1, cl(id)
					lincom _b[_cons] + _b[win]
				   
					reg gain win if known == 1 & catastrophe == 0, cl(id)
					lincom _b[_cons] + _b[win]
					reg loss win if known == 1 & catastrophe == 0, cl(id)
					lincom _b[_cons] + _b[win]

					reg gain win if known == 1 & catastrophe == 1, cl(id)
					lincom _b[_cons] + _b[win]
					reg loss win if known == 1 & catastrophe == 1, cl(id)
					lincom _b[_cons] + _b[win]
				   
					reg gain win known win_known, cl(id)
					reg loss win known win_known, cl(id)
										   

		   
			}
		   
			// Discount factor
			if 1 {
					// See file dataManagement
			}
			
			// Demographics
			if 1{
					tab male if tag == 1
					replace age = age + 17
					su age
			}
               
               
        }
	
}

	
	
	


